package com.example.rbacmanage.controller.background;

import com.example.rbacmanage.common.Result;
import com.example.rbacmanage.entity.app.Classic;
import com.example.rbacmanage.entity.app.Tag;
import com.example.rbacmanage.service.app.ClassicService;
import com.example.rbacmanage.service.app.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


@RestController
@RequestMapping("/background/classic")
public class ClassicController {
    @Autowired
    private ClassicService classicService;

    @GetMapping("/list")
    @PreAuthorize("hasAnyAuthority('background:classic:list')")
    public Result page(Classic classic){
        return Result.success(classicService.getPage(classic));
    }

    @GetMapping("/alllist")
    public Result list(Classic classic){
        return Result.success(classicService.getAll(classic));
    }

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Long id){
        return Result.success(classicService.getById(id));
    }


    @PreAuthorize("hasAnyAuthority('background:classic:add')")
    @PostMapping("/add")
    public Result add(@RequestBody Classic classic){
        classic.setCreateTime(new Date());
        classicService.save(classic);
        return Result.success();
    }
    @PreAuthorize("hasAnyAuthority('background:classic:update')")
    @PutMapping("/update")
    public Result update(@RequestBody Classic classic){
        classicService.update(classic);
        return Result.success();
    }

    @PreAuthorize("hasAnyAuthority('background:classic:remove')")
    @DeleteMapping("/remove")
    public Result remove(@RequestBody Long[] ids){
        classicService.remove(ids);
        return Result.success();
    }
}
